-- 标准半径
local function setRadius(self, radius)
        -- Sqrt because Transform applies scaling exponentially.
        --  300: Game Unit to Pixel conversion.
        -- 1900: Firefighter texture size.
    local scale = math.sqrt(radius * 300 / 1900)
    self.Transform:SetScale(scale, scale, scale)
    return self
end

local function setParentScale(self, parent, radius)
    if parent and parent:IsValid() then
        local scale = math.sqrt(radius * 300 / 1900)
        self.entity:SetParent(parent.entity)
        local s1, s2, s3 = parent.Transform:GetScale()
        self.Transform:SetScale(scale/s1, scale/s2, scale/s3)
        -- self.parent_prefab = parent.prefab
    end
    return self
end

-- 2023.10.22 呼吸：感觉很垃圾啊这个，并不是实际大小
local function setStandardParentScale(self, parent, radius)
    if parent and parent:IsValid() then
        local scale = math.sqrt(radius * 300 / 1900)
        self.entity:SetParent(parent.entity)
        self.Transform:SetScale(scale, scale, scale)
    end
    return self
end

local function setColor(self, color)
    self.AnimState:SetMultColour(unpack(PLAYERCOLOURS[string.upper(color)]))
    self.AnimState:SetAddColour(unpack(PLAYERCOLOURS[string.upper(color)]))
    return self
end


local function setParent(self, inst)
    if inst and inst:IsValid() then
        self.entity:SetParent(inst.entity)
    end
    return self
end

local function setParentHighLight(self, parent, bool)
    if parent and parent:IsValid() then
        if bool == true then
            self:setColor("red")
            self.AnimState:SetLightOverride(1)
            parent.AnimState:SetLightOverride(1)
        else
            self:setColor(bool)
            self.AnimState:SetLightOverride(0)
            parent.AnimState:SetLightOverride(0)
        end
    end
    return self
end

local function setVisable(self, bool)
    if bool then
        self:Show()
    else
        self:Hide()
    end
    return self
end

local function fn()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    local anim = inst.entity:AddAnimState()

    anim:SetBank("firefighter_placement")
    anim:SetBuild("firefighter_placement")
    anim:PlayAnimation("idle")
    anim:SetOrientation(ANIM_ORIENTATION.OnGround)
    anim:SetLayer(LAYER_BACKGROUND)

    -- 官方模板
    -- anim:SetSortOrder(1)
    -- inst.entity:SetCanSleep(false)
    -- inst.persists = false
    -- inst:AddTag("CLASSIFIED")

    inst:AddTag("huxi")
	inst:AddTag("NOBLOCK")
    inst:AddTag("NOCLICK")

    -- "FX"标签使得noclick失效
    -- inst:AddTag("FX")

    inst.setRadius = setRadius
    inst.setColor = setColor
    inst.setParent = setParent
    inst.setParentScale = setParentScale
    inst.setVisable = setVisable
    inst.setParentHighLight = setParentHighLight
    inst.setStandardParentScale = setStandardParentScale

    return inst
end


return Prefab("hrange", fn)